import { reactive } from "vue";
import * as enumSum from "../utils/enum";

const useEnum = (name: keyof typeof enumSum & {}) => {
  const list = (enumSum as Record<string, any>)[name];
  const map = reactive<Record<string, typeof list>>({});

  list?.forEach((e: any) => {
    Reflect.set(map, e.value, e);
  });

  // 需要考虑嵌套的情况了
  const get = (value: any, key: string = "label") => {
    return map[value]?.[key];
  };

  return { map, list, get };
};

export default useEnum;
